package cn.swust.designpatternlearningplatform.dao.sql;

import cn.swust.designpatternlearningplatform.domain.entity.TestPaper;
import org.apache.ibatis.jdbc.SQL;

import java.time.LocalDateTime;

public class TestPaperDaoSql {
    /**
     * @param testId:
      * @return String
     * @author wang
     * description 删除试卷信息里面的相关内容
     * date 2023/5/25 0:40
     */
    public String deleteTestPaper(String testId){
        return new SQL(){
            {
                DELETE_FROM("test_paper");
                WHERE("paper_number=#{testId}");
            }

        }.toString();
    }
    /**
     * @param testPaper1:
      * @return String
     * @author wang
     * description 添加试卷信息
     * date 2023/5/28 13:14
     */
    public String addTestPaper(TestPaper testPaper1){
        String paperNumber=testPaper1.getPaperNumber();
        String testName = testPaper1.getTestName();
        String teacherNumber = testPaper1.getTeacherNumber();
        LocalDateTime startTime = testPaper1.getStartTime();
        LocalDateTime endTime = testPaper1.getEndTime();
        Integer doableTime = testPaper1.getDoableTime();
        Integer topicNumber = testPaper1.getTopicNumber();
        LocalDateTime publishTime = testPaper1.getPublishTime();
        String isPublish = testPaper1.getIsPublish();
        String classNumber = testPaper1.getClassNumber();
        String semester = testPaper1.getSemester();
        Integer testScore=testPaper1.getTestScore();
        return new SQL(){
            {
                INSERT_INTO("test_paper");
                VALUES("paper_number","#{paperNumber}");
                VALUES("test_name","#{testName}");
                VALUES("teacher_number","#{teacherNumber}");
                VALUES("start_time","#{startTime}");
                VALUES("end_time","#{endTime}");
                VALUES("doable_time","#{doableTime}");
                VALUES("topic_number","#{topicNumber}");
                VALUES("test_score","#{testScore}");
                VALUES("publishTime","#{publishTime}");
                VALUES("is_publish","#{isPublish}");
                VALUES("class_number","#{classNumber}");
                VALUES("semester","#{semester}");

            }
        }.toString();
    }
    /**
     * @param testId:
      * @return String
     * @author wang
     * description 通过试卷的id查找试卷的名称
     * date 2023/6/1 16:11
     */
    public String getPaperName(String testId){
        return new SQL(){
            {
                SELECT("test_name");
                FROM("test_paper");
                WHERE("paper_number=#{testId}");
            }
        }.toString();
    }
}
